package com.hzcx.app.simplechat.ui.splash;

import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.hzcx.app.simplechat.R;
import com.hzcx.app.simplechat.base.BaseActivity;
import com.hzcx.app.simplechat.ui.login.LoginActivity;
import com.hzcx.app.simplechat.ui.main.MainActivity;
import com.hzcx.app.simplechat.util.token.TokenUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 欢迎页
 */
public class SplashActivity extends BaseActivity {
    @BindView(R.id.iv_splash)
    ImageView ivSplash;
    @BindView(R.id.tv_app_name)
    TextView tvAppName;

    @Override
    public int getLayout() {
        return R.layout.activity_splash;
    }

    @Override
    public void initPresenter() {

    }

    @Override
    public void initView() {

        tvAppName.setText(getResources().getString(R.string.app_name));

        new Thread(() -> {
            try {
                if (TokenUtils.isTokenExpire()) {
                    Thread.sleep(1000);
                    startActivity(new Intent(SplashActivity.this, MainActivity.class));
                    finish();
                } else {
                    Thread.sleep(1000);
                    startActivity(new Intent(SplashActivity.this, LoginActivity.class));
                    finish();
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
    }

    @Override
    public void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
